package com.cirkana.viewer.share;

import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.EditText;

import com.cirkana.CirkanaActivity;
import com.cirkana.serial.SerializationException;
import com.cirkana.viewer.R;

public class AuthoringTwitterActivity extends CirkanaActivity {

	public static final int RESULT_AUTHORINGTWITTER_OK = 0;

	private WebView webView;
	private EditText pinEditText;
	private Button confirmButton;

	private AuthoringTwitterPassData data;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.authoringtwitter);

		this.webView = (WebView) findViewById(R.id.authoringtwitter_web);
		this.pinEditText = (EditText) findViewById(R.id.authoringtwitter_pin);
		this.confirmButton = (Button) findViewById(R.id.authoringtwitter_confirm);

		this.data = (AuthoringTwitterPassData) getRequest(AuthoringTwitterPassData.class);

		
		this.webView.loadUrl(this.data.getUrl());

		this.confirmButton.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				try {
					data.setPin(pinEditText.getText().toString());
					setResponse(RESULT_AUTHORINGTWITTER_OK, data);
				} catch (SerializationException e) {
					openMessageBox("Error", e.getMessage());
				}
				finish();
			}
		});
	}
}
